﻿namespace Sai.Core.Reporting
{
    using System.Text;

	public class DefaultReportStyler : IReportStyler
	{
		public DefaultReportStyler()
		{
			var styleBuilder = new StringBuilder();
            
            // css reset
			styleBuilder.AppendLine("html,body,div,h1,h2,h3,h4,h5,h6,p,img,dl,dt,dd,ol,ul,li,table,caption,tbody,tfoot,thead,tr,th,td,form,fieldset,embed,object,applet { margin: 0; padding: 0; border: 0; }");

            // general 
            styleBuilder.AppendLine("html, body { background-color:$(BackgroundColour); }");
            styleBuilder.AppendLine("body { color:$(TextColour); font-family:$(FontFamily); font-size:$(FontSize); }");

            // header
            styleBuilder.AppendLine("header { padding: 2em; }");
            styleBuilder.AppendLine("article > header { padding: 0; }");

            styleBuilder.AppendLine("article > header { margin: 0; }");
            styleBuilder.AppendLine("article { background-color: $(ArticleBackgroundColour); margin: 2em; padding: 1em; -webkit-border-top-left-radius: $(BorderRadius); -webkit-border-top-right-radius: $(BorderRadius); -moz-border-radius-topleft: $(BorderRadius); -moz-border-radius-topright: $(BorderRadius); border-top-left-radius: $(BorderRadius); border-top-right-radius: $(BorderRadius); }");

            // tables
            styleBuilder.AppendLine("table { background-color: $(TableBackgroundColour); border-collapse:collapse; border-width:0; empty-cells:show; font-size:1em; margin:0 0 1em; padding:0; width: 100%; }");
            styleBuilder.AppendLine("th, td { background-color:inherit; border: 1px solid $(BorderColour); padding:6px 12px; text-align:left; vertical-align:top; }");
            styleBuilder.AppendLine("td > p:last-child { margin:0; }");
            styleBuilder.AppendLine(".even { background-color: $(ZebraStripeColour); }");
            styleBuilder.AppendLine("caption { display: none; }");
            styleBuilder.AppendLine("code { font-family: $(CodeFontFamily); }");

            // links
            styleBuilder.AppendLine("a:link { color: $(LinkColour); text-decoration: none; }");
            styleBuilder.AppendLine("a:visited { color: $(LinkColour); }");
            styleBuilder.AppendLine("a:hover { text-decoration:underline; }");
            styleBuilder.AppendLine("a:active { text-decoration:underline; }");
            styleBuilder.AppendLine(".toggle { float: right; font-size: 0.85em; }");

            // footer
            styleBuilder.AppendLine("footer { border-top: 1px solid $(BorderColour); background-color: $(BackgroundColour); padding: 2em;  }"); 
            styleBuilder.AppendLine("footer > p { padding: 1em 0; text-align: center; }");

            styleBuilder.AppendLine("ul, li { display: inline; margin-right: 0.5em; }");
            styleBuilder.AppendLine("li:first-child { border-left: none; }");
            styleBuilder.AppendLine("nav { margin: 0; }");
            styleBuilder.AppendLine("section { padding: 0 2em; }");

            const string backgroundColour = "#fff";
            const string articleBackgroundColour = "#f2f2f2";
            const string borderColour = "#eee";
            const string textColour = "#333";
            const string generalFontFamily = "\"HelveticaNeue-Light\",\"Helvetica Neue Light\",\"Helvetica Neue\",sans-serif !important;";
            const string codeFontFamily = "consolas, courier, monospace";
            const string linkColour = "#0088CC";
            const string zebraStripeColour = "#f9f9f9";
            const string tableBackgroundColour = "#fff";
            const string fontSize = "1em"; //; line-height: 1.462em";
            const string borderRadius = "8px";

            styleBuilder.Replace("$(BackgroundColour)", backgroundColour);
            styleBuilder.Replace("$(ArticleBackgroundColour)", articleBackgroundColour);
            styleBuilder.Replace("$(FontFamily)", generalFontFamily);
            styleBuilder.Replace("$(CodeFontFamily)", codeFontFamily);
            styleBuilder.Replace("$(FontSize)", fontSize);
            styleBuilder.Replace("$(TextColour)", textColour);
            styleBuilder.Replace("$(LinkColour)", linkColour);
            styleBuilder.Replace("$(BorderColour)", borderColour);
            styleBuilder.Replace("$(TableBackgroundColour)", tableBackgroundColour);
            styleBuilder.Replace("$(ZebraStripeColour)", zebraStripeColour);
            styleBuilder.Replace("$(BorderRadius)", borderRadius);

			this.StyleTag = styleBuilder.ToString();
		}

		public string HeadTag
		{
			get;
			set;
		}

		public string StyleTag
		{
			get;
			set;
		}

		public string HeadingText
		{
			get;
			set;
		}

		public string FooterText
		{
			get;
			set;
		}

		public bool IsValid
		{
			get { return true; }
		}
	}
}
